#include<cppr.hpp>
using namespace std;
int open_fd(int fd)
{
    if (fd < 0)
    {
        throw "文件打开失败";
    }
    return fd;
}

int main(int argc, char const *argv[])
{

    char buf[1024];
    while (1)
    {
        cout << "请输入文件名：" << endl;
        cin >> buf;
        int fd = open(buf, O_RDONLY);
        try
        {
            fd = open_fd(fd); //抛出异常 ,如果以下还有代码，则不会执行
            cout << "文件打开成功" << endl;
            read(fd, buf, sizeof(buf));
            cout << "文件内容：" << buf << endl;
            break;
        }
        catch (const char *msg)
        {
            cout << msg << endl;
        }
    }
    return 0;
}
